<template>
	<view class="setting-page">
		<view style="height: 10upx;background-color: #F3F3F3;">
			
		</view>
		<view class="setting-module">
			<view class="setting-item border-bottom" @tap="skipToModifyPage">
				<text class="setting-item-title">修改密码</text>
				<view class="setting-item-content">
					<text class="iconfont icon-right"></text>
				</view>
			</view>
			<view class="setting-item">
				<text class="setting-item-title">手机号</text>
				<view class="setting-item-content" @tap="skipToBasicPage">
					<text>{{diyMobile}}</text>
					<text class="iconfont icon-right"></text>
				</view>
			</view>
		</view>
		<view class="setting-module" style="margin-top: 20upx;">
			<view class="setting-item border-bottom" @click="skipToPrivacyPolicy(2)">
				<text class="setting-item-title">用户须知</text>
				<view class="setting-item-content">
					<text class="iconfont icon-right"></text>
				</view>
			</view>
			<view class="setting-item border-bottom" @click="skipToPrivacyPolicy(1)">
				<text class="setting-item-title">隐私政策</text>
				<view class="setting-item-content">
					<text class="iconfont icon-right"></text>
				</view>
			</view>
			<view class="setting-item border-bottom">
				<text class="setting-item-title">关于我们</text>
				<view class="setting-item-content">
					<text class="iconfont icon-right"></text>
				</view>
			</view>
			<view class="setting-item" @click="skipToOpinionPage()">
				<text class="setting-item-title">意见反馈</text>
				<view class="setting-item-content">
					<text class="iconfont icon-right"></text>
				</view>
			</view>
		</view>
		<view class="custom-btn" v-if="isLogin" @tap="loginOut">退出登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				isLogin: false
			}
		},
		computed:{
			diyMobile(){
				if(this.mobile){
					return this.mobile.slice(0,3) + '****' + this.mobile.slice(6)
				}else{
					return ''
				}
			}
		},
		// 导航栏自定义按钮点击事件
		onNavigationBarButtonTap(e) {
			console.log(e);
			if(e.type === 'back'){
				uni.switchTab({
					url: '/pages/mine/mine'
				})
			}
			// // #ifdef APP-PLUS
			// const webView = this.$mp.page.$getAppWebview();
			// // #endif
			// console.log(webView);
		},
		onLoad(){
			
		},
		onShow(){
			this.initInfo()
		},
		methods: {
			initInfo(){
				let userInfo = uni.getStorageSync('userInfo');
				if(userInfo){
					userInfo = JSON.parse(userInfo)
				    this.mobile = userInfo.mobile;
					this.isLogin = true;
				}else{
					this.isLogin = false;
				}
			},
			skipToPrivacyPolicy(type){
				uni.navigateTo({
					url: '/pages/mine/aboutUs/aboutUs?type=' + type
				})
			},
			loginOut() {
				uni.showModal({
					title: "退出提示",
					content: "确认要退出登录吗？",
					success: (res) => {
						console.log(res);
						if (res.confirm) {
							uni.clearStorage();

							// #ifdef APP-PLUS
							
							plus.runtime.quit();  //app退出
							// uni.showToast({
							// 	duration: 2000,
							// 	icon: 'none',
							// 	title: '2秒后将重启'
							// })
							// setTimeout(() => {
							// 	uni.hideToast();
							// 	plus.runtime.restart(); //app重启
							// }, 2000)
							// #endif

							// #ifdef H5 || MP-WEIXIN
							// uni.showToast({
							// 	duration: 2000,
							// 	icon: 'none',
							// 	title: '2秒后将刷新页面'
							// });
							// setTimeout(() => {
							// 	uni.hideToast();
							// 	uni.switchTab({
							// 		url: '/pages/mine/mine'
							// 	})
							// }, 2000)
							// #endif
						}
					}
				})
			},
			skipToModifyPage(){
				let token = uni.getStorageSync('token');
				if(token){
					uni.navigateTo({
						url: '/pages/mine/modify/modify'
					})
				}else{
					uni.showToast({
						title:"您尚未登录",
						icon: 'none'
					})
				}				
			},
			skipToOpinionPage(){
				let token = uni.getStorageSync('token');
				if(token){
					uni.navigateTo({
						url: '/pages/mine/opinionSubmit/opinionSubmit'
					})
				}else{
					uni.showToast({
						title:"您尚未登录",
						icon: 'none'
					})
				}		
			},
			skipToBasicPage(){
				if(!this.isLogin){
					uni.showToast({
						title:"您尚未登录",
						icon: 'none'
					})
					return 
				}
				uni.navigateTo({
					url: '/pages/mine/basic/basic'
				})
			}
		}
	}
</script>

<style scoped>
	.setting-page{
		height: 100%;
		background-color: #F3F3F3;
	}
	.setting-module{
		display: flex;
		flex-direction: column;
		padding: 0 30upx;
		width: 690upx;
		background-color: #FFFFFF;
		color: #333333;
	}
	.setting-item{
		height: 100upx;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.setting-item-title{
		font-size: 30upx;
		color: #333333;
	}
	.setting-item-content{
		color: #999999;
		font-size: 30upx;
	}
	.custom-btn {
		width: 100%;
		height: 100upx;
		text-align: center;
		line-height: 100upx;
		background-color: #FFFFFF;
		color: #FF5D5D;
		margin-top: 198upx;
		font-size: 30upx;
	}
</style>
